﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AIStudio.Service.Quartz.Extensions
{
    public class CronHelper
    {
        public static string DateTime2Cron(DateTime date)
        {
            return date.ToString("ss mm HH dd MM ? yyyy");
        }

        public static DateTime Cron2DateTime(string cron)
        {
            return DateTime.ParseExact(cron, "ss mm HH dd MM ? yyyy", System.Globalization.CultureInfo.CurrentCulture);
        }

        public static DateTimeOffset? DateTime2DateTimeOffset(DateTime? datetime)
        {
            if (datetime == null)
                return null;

            return DateTime.SpecifyKind(datetime.Value, DateTimeKind.Unspecified);
        }

        public static DateTimeOffset? StartTime2DateTimeOffset(DateTime? datetime)
        {
            if (datetime == null)
                return null;

            return DateTime.SpecifyKind(datetime.Value < DateTime.Now? DateTime.Now : datetime.Value, DateTimeKind.Unspecified);
        }

        public static DateTime? DateTimeOffset2DateTime(DateTimeOffset? datetimeoffset)
        {
            if (datetimeoffset == null)
                return null;

            return datetimeoffset.Value.DateTime;
        }
    }
}
